'use strict';

var util = require('util');
var yeoman = require('yeoman-generator');
var fs = require('fs');

var Generator = module.exports = function Generator(args, options){
    yeoman.generators.Base.apply(this, arguments);
    this.log('开始更新需要的库文件');
    this.on('end', function(){
        process.chdir('js');
        this.spawnCommand('bower',['update']);
        process.chdir('../');
    });
};

util.inherits(Generator, yeoman.generators.Base);

Generator.prototype.check = function check(){
    //如果bower.json文件因为publish命令给删除了,那么先恢复
    if(!fs.existsSync('js/bower.json')){
        var source = this.templatePath('../../app/templates/_bower.json');
        this.copy(source, 'js/bower.json');
    }
};